﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Collections;
using System.Data;


namespace BussinesLogic
{
    public class Expediente: BaseObject
    {

        #region Elementos Privados
        private ArrayList _Documentos;
        #endregion

        #region Propiedades Publicas
        public int id { get; set; }
        public string NoExpediente { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime ModifyDate { get; set; }
        public string CreatedBy { get; set; }
        public string ModifiedBy { get; set; }
        public string Descripcion { get; set; }


        public ArrayList Documentos
        {
            get
            {
                if (this._Documentos == null || this._Documentos.Count == 0)
                {
                    DataAccess.Factory.DocumentoFactoryDao tmpFactory = new DataAccess.Factory.DocumentoFactoryDao();
                    this._Documentos = tmpFactory.getDocuments(this.NoExpediente);
                }

                return this._Documentos;
            }
            set
            {
                this._Documentos = value;
            }
        }

        #endregion

        /***********************************/
        public Expediente()
        {            

        }

        public static DataTable getExpedientesTable()
        {
            DataAccess.Factory.ExpedienteFactoryDao tmpFac = new DataAccess.Factory.ExpedienteFactoryDao();

            return tmpFac.getExpedientesTalbe();
        }

        public static Expediente getExpediente(string NoExpediente)
        {
            DataAccess.Factory.ExpedienteFactoryDao tmpFac = new DataAccess.Factory.ExpedienteFactoryDao();

            return tmpFac.getExpediente(NoExpediente);
        }

        public static ArrayList getExpedientes()
        {
            DataAccess.Factory.ExpedienteFactoryDao tmpFac = new DataAccess.Factory.ExpedienteFactoryDao();

            return tmpFac.getExpedientes();
        }

        public Object[] toArrayDisplay
        {
            get
            {
                Object[] tmpObj = new Object[2];

                tmpObj[0] = this.NoExpediente;

                tmpObj[1] = this.Descripcion;

                return tmpObj;
            }
        }

        public int Create()
        {
            try
            {
                DataAccess.Factory.ExpedienteFactoryDao tmpFac = new DataAccess.Factory.ExpedienteFactoryDao();
                this.id = tmpFac.createExpediente(this.xmlObjectDescription());
            }
            catch (Exception ex)
            {
                return -1;
            }
            return 0;
        }

        public string toXML()
        {
            return this.xmlObjectDescription();
        }
    }
}
